
<?php 
	class Muser extends CI_Model{
		protected $_table="user"; 
	public function __construct(){
			parent::__construct();
		}
		public function listAllUser($all,$start){
			$this->db->limit($all,$start);
			return $this->db->get($this->_table)->result_array();
	}
		public function checkLogin($u,$p){
		$this->db->where("username",$u);
		$this->db->where("password",$p);
		$query=$this->db->get($this->_table);
		if($query->num_rows() > 0){
			return $query->row_array();
		}else{
			return FALSE;
		}
			
		} // end checklogin
		
			
		public function countALL(){
			return $this->db->count_all($this->_table) ;// dem so record trong _Table="user"
		}
		
		
			public function checkUsername($user,$id=""){
				if($id !=""){							// edit (id!="") , add (id="")
					$this->db->where("id!=",$id);
				}
				$this->db->where("username",$user); 
				$query= $this->db->get($this->_table) ; 
				
				if($query->num_rows > 0 ){ 				// TRUNG USERNAME TRONG DATABASE
					return FALSE;
				}else{
					return TRUE;
				}
			
			}
			
			public function checkEmail($email,$id=""){
				if($id !=""){							// edit(id!=""), add (id="")
					$this->db->where("id!=",$id);
				}
				$this->db->where("Email",$email); 
				$query= $this->db->get($this->_table) ; 
				
				if($query->num_rows > 0 ){				// trung EMAIL trong DATABASE 
					return FALSE;
				}else{
					return TRUE;
				}
			
			}		


			public function insertData($data_insert){
				$this->db->insert($this->_table,$data_insert);			
			}
			
			public function deleteUser($id){
				$this->db->where('id', $id);
				$this->db->delete($this->_table); 
				
			}
			
			public function getUserById($id){								// lay noi dung cua nguoi dung BY ID (from database)
				$this->db->where('id',$id); 								// lay id truyen vao tu link (base_url) 
				return $this->db->get($this->_table)->row_array(); 			// lay day du lieu voi id  tuong ung ra form
			
			}
			
			public function updatedata($data_update){						// updatedata cho edit thanh vien
				$this->db->where('id',$id);
				$this->db->insert($this->_table,$data_update);
			
			}
		
		
		
	} // end class

?>